package com.stiff.manage.service;

import com.stiff.manage.pojo.ContentCategory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ContentCategoryService extends BaseService<ContentCategory> {
    public void saveContentCategory(ContentCategory contentCategory) {
        contentCategory.setId(null);
        contentCategory.setIsParent(false);
        contentCategory.setSortOrder(1);
        contentCategory.setStatus(1);
        super.save(contentCategory);
        ContentCategory parent = super.queryById(contentCategory.getParentId());
        if(!parent.getIsParent()){
            parent.setIsParent(true);
            super.update(parent);
        }
    }

    public void deleteByContentCategoryIds(String id, List<Object> ids, Long parentId) {
        super.deleteByIds(ContentCategory.class,id,ids);
        ContentCategory record = new ContentCategory();
        record.setParentId(parentId);
        List<ContentCategory> list = super.queryListByWhere(record);
        if(null==list||list.isEmpty()){
            ContentCategory parent = new ContentCategory();
            parent.setParentId(parentId);
            parent.setIsParent(false);
            super.updateSelective(parent);
        }
    }
}
